using UnityEngine;

public class RemotePlayerLookInitialiser : MonoBehaviour
{
	public RuntimeAnimatorController animatorController;

	public GameObject playerModelPrefab;

	public CustomisationConfig.ShadingType shadingType = CustomisationConfig.ShadingType.Normal;

	private TableTennisRemotePlayer _remotePlayerController;

	private PersonaModel _model;

	private Persona myPersona;

	private TableTennisRemotePlayer remotePlayerController
	{
		get
		{
			if (_remotePlayerController == null)
			{
				_remotePlayerController = GetComponent<TableTennisRemotePlayer>();
			}
			return _remotePlayerController;
		}
	}

	private PersonaModel model
	{
		get
		{
			if (_model == null)
			{
				_model = GetComponent<PersonaModel>();
			}
			return _model;
		}
	}

	private void CreatePlayerModel()
	{
		GameObject gameObject = Object.Instantiate(playerModelPrefab);
		gameObject.transform.parent = base.transform;
		gameObject.transform.localPosition = Vector3.zero;
		gameObject.transform.localRotation = Quaternion.identity;
		gameObject.GetComponent<Animator>().runtimeAnimatorController = animatorController;
		remotePlayerController.serveHand = gameObject.transform.Search("HAND LEFT");
	}

	private void OnEnable()
	{
		CreatePlayerModel();
		MatchParameters.MatchParams initParameters = MatchParameters.InitParameters;
		MatchParameters.MatchParams.MultiplayerParams multiplayerParams = initParameters.multiplayerParams;
		StoreItemsConfig.StoreItem itemForTypeAndId = GetItemForTypeAndId(StoreItemsConfig.StoreItem.ItemType.Shoe, multiplayerParams.remoteShoe.shoesId);
		StoreItemsConfig.StoreItem itemForTypeAndId2 = GetItemForTypeAndId(StoreItemsConfig.StoreItem.ItemType.Racket, multiplayerParams.racketId);
		myPersona = new Persona(MatchParameters.InitParameters.multiplayerParams);
		CustomisationConfig.instance.ApplyLooksForPersona(model, myPersona, CustomisationConfig.MatchShaderUseType(shadingType, CustomisationConfig.PlayerType.AI));
	}

	private StoreItemsConfig.StoreItem GetItemForTypeAndId(StoreItemsConfig.StoreItem.ItemType type, string id)
	{
		StoreItemsConfig.StoreItem storeItem = StoreItemsConfig.instance.FindItemWithId(id);
		if (storeItem == null)
		{
			storeItem = StoreItemsConfig.instance.GetItemsForType(type, true)[0];
		}
		return storeItem;
	}
}
